<?php

class Webservices_XML_Format {
    
    public static function convertXMLtoArray($xml){
        $arr = array();
        $dom = simplexml_load_string($xml);
        foreach($dom as $key => $val){
            $tmp = str_split($key);
            $keyStr = "";
            foreach($tmp as $v){
                if(!ctype_lower($v)){
                    $keyStr .= '_'.strtolower($v);
                }else{
                    $keyStr .= $v;
                }
            }
            $arr[$keyStr] = (String)$val;
        }
      
        return $arr;
    }

    /**
     * 
     */
    public static function convertOjbToXml($objs, &$xml) {
        foreach ($objs as $key => $val) {
            
            if (is_object($val)) {
                $xml .= '<' . $key . '>' . Webservices_XML_Format::convertOjbToXml($val, $xml) . '</' . $key . '>';
            } else {
                $xml .= '<' . $key . '>' . $val . '</' . $key . '>';
            }
        }
    }

}